﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace LCSFlashCards
{
    public enum CardTag
    {
        Fresh,
        Successful,
        Failed,
        Delayed
    }
    [Serializable()]
    public class Card<T> : ISerializable
    {
        public CardTag Tag { get; set; }
        public DateTime LastTimeStudied { get; set; }
        public DateTime LastTimeReviewed { get; set; }

        public string FrontTitle { get; set; }
        public T FrontData { get; set; }

        public string BackTitle { get; set; }
        public T BackData { get; set; }

        public int ID { get; set; }

        public Card()
        {
            Tag = CardTag.Fresh;
            LastTimeStudied = DateTime.Parse("1/1/1900") ;
            LastTimeReviewed = DateTime.Parse("1/1/1900");
        }

        public Card(SerializationInfo info, StreamingContext ctxt)
        {
            this.Tag = (CardTag)info.GetValue("Tag", typeof(CardTag));
            this.LastTimeStudied = (DateTime)info.GetValue("LastTimeStudied", typeof(DateTime));
            this.LastTimeReviewed = (DateTime)info.GetValue("LastTimeReviewed", typeof(DateTime));
            this.FrontTitle = (string)info.GetValue("FrontTitle", typeof(string));
            this.FrontData = (T)info.GetValue("FrontData", typeof(T));
            this.BackTitle = (string)info.GetValue("BackTitle", typeof(string));
            this.BackData = (T)info.GetValue("BackData", typeof(T));
            this.ID = (int)info.GetValue("ID", typeof(int));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Tag", this.Tag);
            info.AddValue("LastTimeStudied", this.LastTimeStudied);
            info.AddValue("LastTimeReviewed", this.LastTimeReviewed);
            info.AddValue("FrontTitle", this.FrontTitle);
            info.AddValue("FrontData", this.FrontData);
            info.AddValue("BackTitle", this.BackTitle);
            info.AddValue("BackData", this.BackData);
            info.AddValue("ID", this.ID);
        }
    }
}
